import 'package:flutter/material.dart';
import 'package:flutter_trip/model/common_model.dart';
import 'package:flutter_trip/model/grid_nav_model.dart';
import 'package:flutter_trip/widget/webview.dart';

class LocalNav extends StatelessWidget {
  const LocalNav({Key? key, required this.localNavList}) : super(key: key);

  final List<CommonModel> localNavList;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 68,
      decoration: const BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(7))
      ),
      child: Padding(
        padding: EdgeInsets.all(7),
        child: _items(context),
      ),
    );
  }

  _items(BuildContext context) {
    if (localNavList == null) {
      return null;
    }
    List<Widget> items = [];

    localNavList.forEach((element) {
      items.add(_item(context, element));
    });

    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: items,
    );
  }

  Widget _item(BuildContext context, CommonModel element) {
    return GestureDetector(
      onTap: () {
        Navigator.push(context, MaterialPageRoute(builder: (context)=>
            HiWebView(
              url: element.url,
              statusBarColor: element.statusBarColor,
              hideAppBar: element.hideAppBar,
            )
        ));
      },
      child: Column(
        children: [
          Image.network(
            element.icon!,
            width: 32,
            height: 32,
          ),
          Text(
            element.title!,
            style: TextStyle(fontSize: 12),
          )
        ],
      ),
    );
  }
}
